﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ThuVien;

namespace TranTekBE.Marketing
{
    public partial class Payment : System.Web.UI.Page
    {
        //public List<DanhSachViTriCuaHang> danhSachViTriCuaHang;//= new tb_ViTriCuaHang();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // Get vị trí quảng cáo
                FunctionsUtils.GetDropListViTriQC(droplist_VitriQC);
                // Get loại qc
                FunctionsUtils.GetDropListLoaiQC(droplist_LoaiQC);
                string get_IDQuangCao = FunctionsUtils.GetValueStringFromQueryString("idquangcao", "0");
                FillDataEdit(get_IDQuangCao);
            }
        }
        public void FillDataEdit(string idQuangCao)
        {
            string sql_edit = "SELECT *  FROM QuangCao a Left Join DoiTac b On b.DoiTacId = a.DoiTacId Where QuangCaoId = " + idQuangCao;
            DataSet ds = FunctionsUtils.Database2.ExecuteQuery(sql_edit);
            DataTable dt = ds.Tables[0];
            // Get data
            int DoiTacID = FunctionsUtils.ConvertToInt(dt.Rows[0]["DoiTacId"].ToString(), 0);
            int ViTriID = FunctionsUtils.ConvertToInt(dt.Rows[0]["ViTriID"].ToString(), 0);
            int LoaiQuangCaoId = FunctionsUtils.ConvertToInt(dt.Rows[0]["LoaiQuangCaoId"].ToString(), 0);
            string StartDate = dt.Rows[0]["StartDate"].ToString();
            string EndDate = dt.Rows[0]["EndDate"].ToString();
            string MoneyPerMonth = dt.Rows[0]["MoneyPerMonth"].ToString();
            string DaiDien = dt.Rows[0]["NguoiDaiDien"].ToString();
            string CongTy = dt.Rows[0]["TenCongTy"].ToString();
            string DiaChi = dt.Rows[0]["DiaChi"].ToString();
            string ImgQC = dt.Rows[0]["HinhQuangCao"].ToString();
            // Fill data
            txtDaiDien.Text = DaiDien;
            txtCty.Text = CongTy;
            txtDiaChi.Text = DiaChi;
            droplist_VitriQC.SelectedValue = ViTriID.ToString();
            droplist_LoaiQC.SelectedValue = LoaiQuangCaoId.ToString();
            txtStartDate.Text = StartDate;
            txtEnddate.Text = EndDate;
            txtTienThang.Text = FunctionsUtils.ConvertMoneyVND(MoneyPerMonth);
            imgQC.ImageUrl = ImgQC;
            txtDaiDien.Enabled = false;
            txtCty.Enabled = false;
            txtDiaChi.Enabled = false;
            droplist_VitriQC.Enabled = false;
            droplist_LoaiQC.Enabled = false;
            txtStartDate.Enabled = false;
            txtEnddate.Enabled = false;
            txtTienThang.Enabled = false;

        }

        protected void btnAddEvent_Click(object sender, EventArgs e)
        {

        }
        //public void VitriQC()
        //{
        //    string sql = "SELECT * FROM ViTriCuaHang";

        //    var ds = FunctionsUtils.Database2.ExecuteQuery(sql);
        //    if (ds != null && ds.Tables.Count > 0)
        //    {
        //        DataTable dt = ds.Tables[0];
        //        var ListViTriCuaHang = dt.AsEnumerable().Select(c => new tb_ViTriCuaHang()
        //        {
        //            ViTriId = c.Field<int>("ViTriId"),
        //            TenViTri = c.Field<string>("TenViTri"),
        //            CuaHang = c.Field<string>("CuaHang")
        //        }).ToList<tb_ViTriCuaHang>();
        //        danhSachViTriCuaHang = ListViTriCuaHang.GroupBy(c => c.CuaHang).Select(c => new DanhSachViTriCuaHang()
        //        {
        //            CuaHang = c.Key,
        //            ListViTriCuaHang = ListViTriCuaHang.Where(v => v.CuaHang == c.Key).ToList()
        //        }).ToList();

        //    }


        //}

        
    }
}